package com.igeek.d0611;

/**
 * @Author: zhiyu
 * @Date:18:07
 * @DESC:
 */
public class Test2{
    public static void main(String[] args) {
        DemoRunable demoRunable = new DemoRunable();
        Thread th1 = new Thread(demoRunable,"线程1");
        Thread th2 = new Thread(demoRunable,"线程2");
        th1.start();
        th2.start();
    }
}
class DemoRunable implements Runnable {
    private int i = 1;
    @Override
    public void run() {
//        for (i=i; i<=100 ; i++) {
//            String name = Thread.currentThread().getName();
//            System.out.println(name+":"+(i));
//        }
        while(true){
            synchronized (this) {
                notify();
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                if(i<=100){
                    String name = Thread.currentThread().getName();
                    System.out.println(name+":"+(i++));
                    try {
                        wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }else {
                    break;
                }
            }
        }
    }
}